home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
-
- File: Common.h
-
- Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
-
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- *************************************************************************************/
-
- #ifndef __COMMON__
- #define __COMMON__
-
- #include <stdlib.h>
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __MACTYPES__
- #include <MacTypes.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
-
- /*
- * Debugging flags -- should be set by prefix file or command line
- */
-
- #ifndef DEBUG_NOISY
- #define DEBUG_NOISY 0
- #endif
-
- #ifndef DEBUG
- #if DEBUG_NOISY
- #define DEBUG 1
- #else
- #define DEBUG 0
- #endif
- #endif
-
-
- /*
- * Validation
- * CHECK(int test, int err) is used with a non-void (typically OSStatus) return type.
- * CHECK_RETURN(int test) is used with a void return type.
- */
-
- #if DEBUG_NOISY
- #define FAIL_IF(cond, handler) {if((cond)){DebugStr("\pCHECK(" #cond ") failed in " __FILE__ " at " DEBUG_STR(__LINE__)); goto handler;}}
- #define DEBUG_CODE(e) e
- #define DEBUG_STR(x) DEBUG_VAL(x)
- #define DEBUG_VAL(x) #x
- #define CHECK(test,err) {if(!(test)){DebugStr("\pCHECK(" #test ", " #err ") failed in " __FILE__ " at " DEBUG_STR(__LINE__)); return (err);}}
- #define CHECK_RETURN(test) {if(!(test)){DebugStr("\pCHECK_RETURN(" #test ") failed in " __FILE__ " at " DEBUG_STR(__LINE__)); return;}}
- #define NAG(test,str,err) {if(!(test)){DebugStr("\p" #str ); return (err);}}
- #define NAG_RETURN(test,str) {if(!(test)){DebugStr("\p" #str ); return;}}
- #define WARNING(test, str) {if(!(test)){DebugStr("\p" #str);}}
- #define RES_WARNING(str) { if (ResError()) {DebugStr("\p" #str);}}
- #define QD_WARNING(str) { if (QDError()) {DebugStr("\p" #str);}}
- #elif DEBUG
- #define FAIL_IF(cond, handler) {if((cond)){DebugStr("\pCHECK(" #cond ") failed in " __FILE__ " at " DEBUG_STR(__LINE__)); goto handler;}}
- #define DEBUG_CODE(e) e
- #define CHECK(test,err) {if(!(test))return (err);}
- #define CHECK_RETURN(test) ((void)0)
- #define NAG(test,str,err) {if(!(test))return (err);}
- #define NAG_RETURN(test,str) {if(!(test))return;}
- #define WARNING(test, str) ((void)0)
- #define RES_WARNING(str) ((void)0)
- #define QD_WARNING(str) ((void)0)
- #else
- #define FAIL_IF(cond, handler) {goto handler;}
- #define DEBUG_CODE(e) ((void)0)
- #define CHECK(test,err) ((void)0)
- #define CHECK_RETURN(test) ((void)0)
- #define NAG(test,str,err) ((void)0)
- #define NAG_RETURN(test,str) ((void)0)
- #define WARNING(test, str) ((void)0)
- #define RES_WARNING(str) ((void)0)
- #define QD_WARNING(str) ((void)0)
- #endif
-
-
- /*
- * Thumbprints
- */
-
- typedef enum Thumbprint {
- kThumbprintDead = 'dead', /* Not a valid object */
- kThumbprintListener = 'lsnr', /* A sound Listener, subclass of Spatial */
- kThumbprintSource = 'ssrc' /* A sound Source, subclass of Spatial */
- } Thumbprint;
-
-
- /*
- * Memory management
- */
-
- #define HandleAlloc(size) NewHandle(size)
- #define HandleFree(p) DisposeHandle(p)
- #define HandleResize(p,size) SetHandleSize(p,size)
- #define HandleLock(p) HLock((Handle)p)
- #define HandleUnlock(p) HUnlock((Handle)p)
-
- #define SysHandleAlloc(size) NewHandleSys(size)
- #define SysHandleFree(p) DisposeHandle(p)
- #define SysHandleResize(p,size) SetHandleSize(p,size)
- #define SysHandleLock(p) HLock(p)
- #define SysHandleUnlock(p) HUnlock(p)
-
-
- void* SysHandleRealloc(
- void* p,
- UInt32 size);
-
- #define PtrAlloc(size) NewPtr(size)
- #define PtrFree(p) DisposePtr(p)
-
- void* PtrRealloc(
- void* p,
- UInt32 size);
-
- #define SysPtrAlloc(size) NewPtrSys(size)
- #define SysPtrFree(p) DisposePtr(p)
-
- void* SysPtrRealloc(
- void* p,
- UInt32 size);
-
-
-
- /*
- * Pascal string fun
- */
-
- // Removed because it's kinda bogus jwo 10/21
- //#define CopyPascalString(dst,src) BlockMove(src,dst,(src)[0]+1)
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif /* __COMMON__ */
-